package com.example.project.controller.project;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.project.annotation.Log;
import com.example.project.core.controller.BaseController;
import com.example.project.core.domain.AjaxResult;
import com.example.project.core.page.TableDataInfo;
import com.example.project.entity.Tracker;
import com.example.project.enums.BusinessType;
import com.example.project.service.TrackerService;
import com.example.project.utils.poi.ExcelUtil;

/**
 * 跟踪类型Controller
 * 
 * @author ruoyi
 * @date 2025-09-19
 */
@Controller
@RequestMapping("/project/tracker")
public class TrackerController extends BaseController {

	private String prefix = "pm/tracker";

	@Autowired
	private TrackerService tTrackersService;

	@RequiresPermissions("project:tracker:view")
	@GetMapping()
	public String tracker() {
		return prefix + "/tracker";
	}

	/**
	 * 查询跟踪类型列表
	 */
	@RequiresPermissions("project:tracker:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Tracker tracker) {
		startPage();
		List<Tracker> list = tTrackersService.selectTTrackersList(tracker);
		return getDataTable(list);
	}

	/**
	 * 导出跟踪类型列表
	 */
	@RequiresPermissions("project:tracker:export")
	@Log(title = "跟踪类型", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Tracker tTrackers) {
		List<Tracker> list = tTrackersService.selectTTrackersList(tTrackers);
		ExcelUtil<Tracker> util = new ExcelUtil<Tracker>(Tracker.class);
		return util.exportExcel(list, "跟踪类型数据");
	}

	/**
	 * 新增跟踪类型
	 */
	@RequiresPermissions("project:tracker:add")
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存跟踪类型
	 */
	@RequiresPermissions("project:tracker:add")
	@Log(title = "跟踪类型", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Tracker tTrackers) {
		tTrackers.setCreateBy(getLoginName());
		return toAjax(tTrackersService.insertTTrackers(tTrackers));
	}

	/**
	 * 修改跟踪类型
	 */
	@RequiresPermissions("project:tracker:edit")
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		Tracker tracker = tTrackersService.selectTTrackersById(id);
		mmap.put("tracker", tracker);
		return prefix + "/edit";
	}

	/**
	 * 修改保存跟踪类型
	 */
	@RequiresPermissions("project:tracker:edit")
	@Log(title = "跟踪类型", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Tracker tTrackers) {
		tTrackers.setUpdateBy(getLoginName());
		return toAjax(tTrackersService.updateTTrackers(tTrackers));
	}

	/**
	 * 删除跟踪类型
	 */
	@RequiresPermissions("project:tracker:remove")
	@Log(title = "跟踪类型", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(tTrackersService.deleteTTrackersByIds(ids));
	}
}
